
####Figure 1

###set working directory in the next line
setwd("") 

all<-read.csv("all_modularity.csv")
dyads<-read.csv("dyads.csv")
years<-unique(dyads$year)
years<-sort(years)
years<-subset(years,years>1949)

ml<-all$ml
le<-all$le
fg<-all$fg
wt<-all$wt
sg<-all$sg
eb<-all$eb

plotname<-paste("modularity_comparison.jpg")
jpeg(filename = plotname, width = 1000, height =600,
     units = "px", pointsize = 12, quality = 100, bg = "white",
     res = NA, restoreConsole = TRUE)

plot(years,ml,pch=19,ylab="",ylim=c(0,0.08),type="n",
     xlab="",bty="n",
     cex=1.0)
lines(years,ml,lwd=2)
lines(years,le,col="blue",lwd=2)
lines(years,fg,col="red",lwd=2)
lines(years,wt,col="green",lwd=2)
lines(years,sg,col="yellow",lwd=2)
lines(years,eb,col="grey",lwd=2)

legend(x=c(1950,1964.5),y=c(0.028,0.058),legend=c("         ","         ","         ","         "))

text(x=1950.5,y=.056,"Black=Louvain",cex=1.2,col="black",pos = 4) 
text(x=1950.5,y=.051,"Blue=Leading Eigenvector",cex=1.2,col="blue",pos = 4) 
text(x=1950.5,y=.046,"Red=Fast and Greedy",cex=1.2,col="red",pos = 4) 
text(x=1950.5,y=.041,"Green=Walktrap",cex=1.2,col="green",pos = 4) 
text(x=1950.5,y=.036,"Yellow=Spinglass",cex=1.2,col="yellow",pos = 4)
text(x=1950.5,y=.031,"Grey=Edge Betweenness",cex=1.2,col="grey",pos = 4)
mtext("Modularity",side=2,line=2.5)
mtext("Year",side=1,line=2.5)

dev.off()

####Figure 2

###set working directory in the next line
setwd("") 

modularity<-read.csv("modularity_bipartite.csv")
modularity<-modularity[,2]

plot(years,modularity,pch=19,ylab="",bty="n",
     xlab="",
     cex=1.0)
lines(years,modularity)
mtext("Modularity",side=2,line=2.5)
mtext("Year",side=1,line=2.5)

savePlot("modularity_bipartite",type="eps")

####Figure 3

###set working directory in the next line
setwd("") 

ml<-read.csv("louvain_modularity_nonecon.csv")

plot(years,ml[,2],pch=19,ylab="",bty="n",
     xlab="",
     cex=1.0)
lines(years,ml[,2])
mtext("Modularity",side=2,line=2.5)
mtext("Year",side=1,line=2.5)

savePlot("modularitybyyear_non_econ",type="eps")

dev.off()
